<include file="Public/header" title="地址管理" bdstyle="background:#f2f2f2"/>
<include file="Public/header_back"/>
<foreach name="address_list" item="val">
    <article class="address-manage">
        <div class="address-manage-head flex-justify">
            <span>{$val.consignee}</span>
            <span>{$val.mobile}</span>
        </div>
        <p>{$val.address}</p>
        <div class="address-select-foot flex-justify">
            <div class="address-select" >
                <input type="checkbox" {:$val['is_default']=='1'?'checked':''} name="default_address" value="{$val.address_id}"/>
                <i class="iconfont"></i>
                设为默认地址
            </div>
            <div class="address-edit">
                <a href="{:U('Ucenter/editAddress',array('address_id'=>$val['address_id']))}">编辑</a>
                <a href="javascript:void(0)" onclick="deleteAddress('{$val.address_id}')">删除</a>
            </div>
        </div>
    </article>
</foreach>
    <footer class="create-address">
        <a href="{:U('Ucenter/editAddress')}"><i>+</i><span>新建地址</span></a>
    </footer>
<script>
$(function(){
	$('input[name=default_address]').click(function(){
		if($(this).prop('checked')){
			var address_id = $.trim($(this).val())
			$.post(
				"{:U('setDefaultAddress')}",
				{address_id:address_id},
				function(data){
					if(data.status == '1'){
						location.reload()
					}else{
						layer.msg(data.info)
					}
				}
			)
		}
	})
})
function deleteAddress(address_id){
	if(confirm('确定要删除该地址吗？')){
		$.post(
			"{:U('deleteAddress')}",
			{address_id:address_id},
			function(data){
				if(data.status == '1'){
					location.reload();
				}else{
					layer.msg(data.info);
				}
			}
		)
	}
}
</script>
<include file="Public/footer"/>


